import React from 'react';

const map = { weekly: 'w', monthly: 'm', quarterly: 'q' };

/**
 * 0: 能力评估
 * 1: 任务结果
 * 2: 季度绩效
 * 3: 人事评估
 * @export
 * @returns {w:{showAssess,showTask,showKPI,showHR},m:{},q:{}}
 */
export default function useAssessSetting(data) {
    const { evaluationSetting = [] } = data;
    // const evaluationSetting = [
    //     { period: 'weekly', periodDefine: '0', indicators: '1,2,3' },
    //     { period: 'monthly', periodDefine: '0', indicators: '1,2,3,4' },
    //     { period: 'quarterly', periodDefine: '0', indicators: '1,2,3,4' }
    // ];

    const settingMap = React.useMemo(() => {
        const final = { w: {}, m: {}, q: {} };
        evaluationSetting.forEach(({ period = '', indicators = '' }) => {
            final[map[period]] = {
                // showAssess: indicators.includes('0'),
                showAssess: true,
                showTask: indicators.includes('1'),
                showKPI: indicators.includes('2'),
                showHR: indicators.includes('3')
            };
        });
        return final;
    }, [evaluationSetting]);

    return settingMap;
}
